import axios from "axios";
import { Toast } from "vant";
import store from "../store";
const service = axios.create({
  baseURL:
    "http://121.40.159.226:7300/mock/6193260b5e1e7941050f5e38/watermelon", // api的base_url
  timeout: 10000, // 请求超时时间
});
// 添加请求拦截器
service.interceptors.request.use((config) => {
  Toast.loading({
    message: "加载中...",
    forbidClick: true,
    loadingType: "spinner",
  });
  const token = store.state.token;
  token && (config.headers.Authorization = token);
  return config;
});
// 添加响应拦截器
service.interceptors.response.use(
  (res) => {
    Toast.clear();
    return res.data;
  },
  (err) => {
    console.log(err);
  }
);

export default service;
